package com.hd.crdao.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hd.crdao.R;
import com.hd.crdao.base.BaseActivity;
import com.hd.crdao.bean.ChildUserBean;
import com.hd.crdao.config.Config;
import com.hd.crdao.utils.ALog;
import com.hd.crdao.utils.SPUtils;
import com.hd.crdao.utils.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 *
 *@author Programming
 *@date 2017/7/7 0007
 */
public class ChildUserActivity extends BaseActivity {

    @BindView(R.id.user_properties)
    TextView mUserProperties;
    @BindView(R.id.head_pic)
    CircleImageView mHeadPic;
    @BindView(R.id.tvName)
    TextView mTvName;
    @BindView(R.id.arrow)
    ImageView mArrow;
    @BindView(R.id.settings)
    ImageView mSettings;

    @BindView(R.id.loancar)
    TextView mLoancar;
    @BindView(R.id.publishcarsource)
    TextView mPublishCarsouce;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_childuser;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initData() {
        String childuser = SPUtils.getString("childuser", "");
        ALog.d(childuser);
        ChildUserBean childUserBean = new Gson().fromJson(childuser, ChildUserBean.class);
        ChildUserBean.DataBean childUserBeanData = childUserBean.getData();

        mTvName.setText(childUserBeanData.getName());
        String[] userTypes = getResources().getStringArray(R.array.userType);
        int usertype = childUserBean.getUsertype();
        mUserProperties.setText(userTypes[usertype] + "---" + childUserBean.getCarBusiness().getArea().getName());
        SPUtils.saveString(Config.businessId, childUserBean.getCarBusiness().getId());
        SPUtils.saveString(Config.userId, childUserBean.getCarBusiness().getUser().getId());

    }

    @Override
    protected void initListener() {

    }


    @OnClick({R.id.arrow, R.id.settings, R.id.loancar, R.id.publishcarsource})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.arrow:
                ALog.d("跳转到修改个人信息");
                break;
            case R.id.settings:
                Intent intent = new Intent(UIUtils.getContext(), SettingsActivity.class);
                intent.putExtra("flag", "childuser");
                startActivity(intent);
                finish();
                break;

            case R.id.loancar:
                startActivity(new Intent(UIUtils.getContext(), NewLoanCarActivity.class));
                break;
            case R.id.publishcarsource:
                Intent enterance = new Intent(UIUtils.getContext(), ReleaseActivity.class);
                enterance.putExtra("isFromMain", false);
                startActivity(enterance);
                break;


        }
    }

    @Override
    public void onBackPressed() {
        startActivity(new Intent(UIUtils.getContext(), LoginActivity.class));
        finish();
    }
}
